package com.lamthun.common.client.resp;

import com.lamthun.common.client.CommonCode;
import com.lamthun.common.client.DTO;
import com.lamthun.common.client.ResponseCode;

/**
 * 对返回的定义, 这里一般约定一个返回代码和返回message
 *
 * @author lilei
 */
public class SingleResponse extends DTO {
    private static final long serialVersionUID = -1L;

    private String code;

    private String message;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public String toString() {
        return "SingleResponse [code=" + code + ", message=" + message + "]";
    }

    public static SingleResponse buildResponse(String code, String message) {
        SingleResponse singleResponse = new SingleResponse();
        singleResponse.setCode(code);
        singleResponse.setMessage(message);
        return singleResponse;
    }

    public static SingleResponse buildResponse(ResponseCode responseCode) {
        return buildResponse(responseCode.getCode(), responseCode.getMessage());
    }

    /**
     * 通用成功返回结果
     */
    public static SingleResponse success() {
        return buildResponse(CommonCode.SUCCESS.getCode(), CommonCode.SUCCESS.getMessage());
    }

    /**
     * 未知的失败返回结果
     */
    public static SingleResponse failed() {
        return buildResponse(CommonCode.FAILED.getCode(), CommonCode.FAILED.getMessage());
    }
}
